cd ..
echo -e "\e[32m >>>>>>>> start install \e[0m"
# npm install
echo -e "\e[32m >>>>>>>> install finish \e[0m"

echo -e "\e[32m >>>>>>>> start build \e[0m"
# npm run build
echo -e "\e[32m >>>>>>>> build finish \e[0m"

cp -r dist server
cd server

# 镜像名 容器名 端口
imgName="vuenode_img:1.0"
containerName="vuenode_img_container"
port=9527

# 如果容器存在
docker inspect ${containerName} -f '{{.Name}}' > /dev/null
if [ $? -eq 0 ] ;then
    echo -e "\e[32m >>>>>>>> 清除老容器 \e[0m"
    docker rm -f ${containerName}
    # else
    #     echo "docker don't exist"
fi

# 如果镜像已经存在
if [[ "$(docker images -q ${imgName} 2> /dev/null)" != "" ]];
then
    echo -e "\e[32m >>>>>>>> 清除老镜像 \e[0m"
    docker rmi -f ${imgName}
    # else
    #     echo "image not exist"
fi

echo -e "\e[32m >>>>>>>> 打包 \e[0m"
docker build -t ${imgName} .

echo -e "\e[32m >>>>>>>> 创建容器，访问地址:  http://localhost:${port} \e[0m"
docker run -d --name ${containerName} -p ${port}:3000 ${imgName}

# echo -e "\e[30m 黑色 \e[0m"
# echo -e "\e[31m 红色 \e[0m"
# echo -e "\e[32m 绿色 \e[0m"
# echo -e "\e[33m 黄色 \e[0m"
# echo -e "\e[34m 蓝色 \e[0m"
# echo -e "\e[35m 紫色 \e[0m"
# echo -e "\e[36m 青色 \e[0m"
# echo -e "\e[37m 白色 \e[0m"